package cn.com.api.controller;

import java.io.PrintWriter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiSmslog;
import cn.com.api.entity.ApiT_specification;
import cn.com.api.entity.ApiShop;
import cn.com.api.entity.ApiShoucang;
import cn.com.api.service.ApiConllectionService;
import cn.com.api.service.ApiT_specificationService;
import cn.com.api.service.ApiSmslogService;
import cn.com.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping(Utils.SYS_API + "spec/")
public class ApiT_specificationController {
	@Autowired
	private ApiT_specificationService apiT_specificationService;
	@Autowired
	private ApiSmslogService apiSmslogService;
	@Autowired
	private ApiConllectionService conllectService;

	/**
	 * insert
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Transactional
	@RequestMapping(value = "insertT_specification")
	public void insertT_specification(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String spec_name = request.getParameter("spec_name");
		String spec_memo = request.getParameter("spec_memo");
		Map<String, Object> map = new HashMap<String, Object>();

		if (spec_name != null && !"".equals(spec_name.trim())) {
			ApiT_specification t_spec = new ApiT_specification();
			t_spec.setSpec_name(spec_name);
			t_spec.setSpec_memo(spec_memo);
			apiT_specificationService.insertT_specification(t_spec);
		}

		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

	//
	@RequestMapping("/findT_specifications")
	public void findT_specifications(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();

		List<ApiT_specification> list = null; // apiT_specificationService.;

		Integer flag = 0;
		if (list.size() >= 1) {
			flag = 1;
		} else {
			flag = 0;
		}
		response.setCharacterEncoding("UTF-8");
		map.put("state", flag);
		map.put("data", list);
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

	/**
	 * 根据id查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_specificationById")
	public void findT_specificationById(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String id = request.getParameter("id");
		ApiT_specification t_spec = apiT_specificationService
				.findT_specificationById(id);

		// response
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put("datas", t_spec);
		out.print(JsonUtil.object2json(map));
		out.close();
	}

}
